const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.EditBox)
    inputName: cc.EditBox = null;

    onLoad() {
        if (!cc.sys.isNative && cc.sys.isMobile) {
            var cvs = this.node.getComponent(cc.Canvas);
            cvs.fitHeight = true;
            cvs.fitWidth = true;
        }
        this.onRandomBtnChilked();
        
        // cc.vv.debug && this.onBtnConfirmClicked();
    }

    /**
     * 随机创建昵称
     */
    onRandomBtnChilked(){
        const names = [
            "上官",
            "欧阳",
            "东方",
            "端木",
            "独孤",
            "司马",
            "南宫",
            "夏侯",
            "诸葛",
            "皇甫",
            "长孙",
            "宇文",
            "轩辕",
            "东郭",
            "子车",
            "东阳",
            "子言",
        ];

        const names2 = [
            "雀圣",
            "赌侠",
            "赌圣",
            "稳赢",
            "不输",
            "好运",
            "自摸",
            "有钱",
            "土豪",
        ];
        const idx = Math.floor(Math.random() * (names.length - 1));
        const idx2 = Math.floor(Math.random() * (names2.length - 1));
        this.inputName.string = names[idx] + names2[idx2];
    }

    /**
     * 创建好昵称，登陆按钮
     */
    onBtnConfirmClicked(){
        if(!this.inputName.string){
            this.inputName.string = '请输入昵称';
            return;
        }
        cc.vv.userMgr.create(this.inputName.string);
    }

}
